#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        int i = 1;
        ans = 0;
        while (i < n) {
            int tmp = i;
            while (tmp) {
                i += tmp % 10;
                tmp /= 10;
            }
            ans++;
        }
        if (i == n) cout << ans << '\n';
        else cout << -1 << '\n';
    }
    return 0;
}